package Z.dailyExercise.April;

import java.util.ArrayList;
import java.util.List;

public class _46全排列 {

    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        List<Integer> track = new ArrayList<>();
        backtrack(nums,track);
        return res;


    }

    public void backtrack(int[] nums,List<Integer> track){

        //结束条件
        if (track.size() == nums.length){
            res.add(new ArrayList<>(track));
        }

        for (int i = 0; i < nums.length; i++) {
            //做选择
            if (track.contains(nums[i])){
                continue;
            }
            track.add(nums[i]);

            backtrack(nums,track);

            track.remove(track.size()-1);
            
        }
    }

}
